//
//  HandyServicVC.m
//  智慧小区
//
//  Created by 高永杨 on 2017/3/19.
//  Copyright © 2017年 zhongchuang. All rights reserved.
//

#import "HandyServicVC.h"
#import "HeadVieCell.h"



@interface HandyServicVC ()
@property (weak, nonatomic) IBOutlet UICollectionView *CollectV;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *nameHandyArr;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *imageHandyArr;

/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *nameTripArr;
@property(nonatomic,strong)NSMutableArray *imageTripArr;

@end

@implementation HandyServicVC
-(NSMutableArray *)nameTripArr
{
    if (!_nameTripArr) {
        _nameTripArr = [NSMutableArray array];
         NSArray *arr1 = @[@"同向拼车",@"定制班车",@"共享汽车"];
        [_nameTripArr addObject:arr1];
    }
    return _nameTripArr;
}
-(NSMutableArray *)imageTripArr
{
    if (!_imageTripArr) {
        _imageTripArr = [NSMutableArray array];
        NSArray *arr1 = @[@"拼车",@"班车",@"汽车"];
        [_imageTripArr addObject:arr1];
    }
    return _imageTripArr;
}

-(NSMutableArray *)nameHandyArr
{
    if (!_nameHandyArr) {
        _nameHandyArr = [NSMutableArray array];
        NSArray *arr1 = [NSArray arrayWithObjects:@"智能医疗",@"智能养老",@"金融服务", nil];
        NSArray *arr2 = @[@"装修装饰",@"保险服务",@"法律服务"];
        NSArray *arr3 = @[@"家政服务"];
        [_nameHandyArr addObject:arr1];
        [_nameHandyArr addObject:arr2];
        [_nameHandyArr addObject:arr3];
    }
    return _nameHandyArr;
}
-(NSMutableArray *)imageHandyArr
{
    if (!_imageHandyArr) {
        _imageHandyArr = [NSMutableArray array];
        NSArray *arr1 = [NSArray arrayWithObjects:@"智能医疗图标",@"智能养老图标",@"金融服务图标", nil];
        NSArray *arr2 = @[@"装修装饰图标",@"保险服务图标",@"法律服务图标"];
        NSArray *arr3 = @[@"家政服务图标"];
        [_imageHandyArr addObject:arr1];
        [_imageHandyArr addObject:arr2];
        [_imageHandyArr addObject:arr3];
    }
    return _imageHandyArr;
}
-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden = YES;
    self.navigationItem.title = @"便民服务";
    [self setNav:self];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    // 设置item尺寸
    layout.itemSize = CGSizeMake(GyyScreenW/3, (GyyScreenH-64-50-130)/4);
    // 设置item之间的间隔
    layout.minimumInteritemSpacing = 0;
    // 设置行之间间隔
    //        layout.minimumLineSpacing = 20;
    // 设置组的内边距
    //        layout.sectionInset = UIEdgeInsetsMake(20, 0, 0, 0);
    self.CollectV.collectionViewLayout = layout;
    //        [self.collectVie registerClass:[HandyCell class] forCellWithReuseIdentifier:@"cellID"];
    [self.CollectV registerNib:[UINib nibWithNibName:NSStringFromClass([HeadVieCell class]) bundle:nil] forCellWithReuseIdentifier:@"collect"];
    // Do any additional setup after loading the view from its nib.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    switch (self.tripServiceType) {
        case HandyService:
            return [self.imageHandyArr[section] count];
            break;
        case trip:
            return [self.nameTripArr[section] count];
            break;
        default:
            break;
    }
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HeadVieCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collect" forIndexPath:indexPath];
    //    cell.imageV.image = [UIImage imageNamed:self.imageArr[indexPath.section][indexPath.item]];
    switch (self.tripServiceType) {
        case HandyService:
            cell.imageV.image = [UIImage imageNamed:self.imageHandyArr[indexPath.section][indexPath.item]];
            cell.labelText.text = self.nameHandyArr[indexPath.section][indexPath.item];
            NSLog(@"----%d---%d",indexPath.item,indexPath.section);
            break;
        case trip:
            cell.imageV.image = [UIImage imageNamed:self.imageTripArr[indexPath.section][indexPath.item]];
            cell.labelText.text = self.nameTripArr[indexPath.section][indexPath.item];
            break;

    }
   
    //    cell.labelText.text = self.nameArr[indexPath.section][indexPath.item];
    return cell;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  
    switch (self.tripServiceType) {
        case HandyService:
             return self.imageHandyArr.count;
            break;
        case trip:
            return self.nameTripArr.count;
            break;
        default:
            break;
    }
   
}

//-(void)setButtonContentCenter:(UIButton *) btn
//
//{
    //    for (int i = 0; i<7; i++) {
    //        int lie = i/3;
    //        int row = i%3;
    //        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    //        btn.frame = CGRectMake(row*GyyScreenW/3, lie*(GyyScreenH-200)/3, GyyScreenW/3, (GyyScreenH-200)/3);
    //        [btn setTitle:self.nameArr[i] forState:UIControlStateNormal];
    //        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    //        [btn setImage:[UIImage imageNamed:self.imageArr[i]]  forState:UIControlStateNormal];
    //        [self.view addSubview:btn];
    //        [self setButtonContentCenter:btn];
    //    }
    //
    //    CGSize imgViewSize,titleSize,btnSize;
    //
    //    UIEdgeInsets imageViewEdge,titleEdge;
    //
    //    CGFloat heightSpace = 10.0f;
    //
    //
    //
    //    //设置按钮内边距
    //
    //    imgViewSize = btn.imageView.bounds.size;
    //
    //    titleSize = btn.titleLabel.bounds.size;
    //
    //    btnSize = btn.bounds.size;
    //
    //
    //
    //    imageViewEdge = UIEdgeInsetsMake(heightSpace,0.0, btnSize.height -imgViewSize.height - heightSpace, - titleSize.width*1.5);
    //
    //    [btn setImageEdgeInsets:imageViewEdge];
    //
    //    titleEdge = UIEdgeInsetsMake(imgViewSize.height +heightSpace, - imgViewSize.width, 0.0, 0.0);
    //    
    //    [btn setTitleEdgeInsets:titleEdge];
    
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
